package com.pdformparent;


// SimpleInputView.java
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.dengpp.pdform.base.BaseCustomFormView;

/**
 * 简单的输入框自定义视图
 */
public class SimpleInputView extends BaseCustomFormView {
    private EditText editText;
    private String currentValue = "";

    @Override
    protected View onCreateView(Context context) {
        LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);

        editText = new EditText(context);
        editText.setHint("请输入内容");

        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                currentValue = s.toString();
                notifyValueChanged(currentValue);
            }
        });

        layout.addView(editText);
        return layout;
    }

    @Override
    protected void onBindData(Object value) {
        if (value != null) {
            currentValue = value.toString();
            editText.setText(currentValue);
        }
    }

    @Override
    public Object getCurrentValue() {
        return currentValue;
    }
}
